  //
//  WelcomeView.m
//  Nooryes
//
//  Created by 高博昆 on 15/6/26.
//  Copyright (c) 2015年 Jason. All rights reserved.
//

#import "WelcomeView.h"

@interface WelcomeView ()<UIScrollViewDelegate>

@property (nonatomic ,strong) UIScrollView *scrollView;

//@property (nonatomic, strong) NSTimer *timer;

@property (nonatomic, strong) UIButton *gotoButton;

@end

@implementation WelcomeView

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    _scrollView.delegate = self;
    _scrollView.contentSize = CGSizeMake(kScreenWidth * 4, kScreenHeight);
    _scrollView.pagingEnabled = YES;
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.bounces = YES;
    [self addImageViews];
    [self.view addSubview:_scrollView];
    
    _gotoButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 80, 25, 60, 30)];
    [_gotoButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
    _gotoButton.layer.borderColor = [[UIColor whiteColor] CGColor];
    _gotoButton.layer.borderWidth = 1.0;
    _gotoButton.layer.masksToBounds = YES;
    _gotoButton.layer.cornerRadius = 4;
    [_gotoButton setBackgroundColor:[UIColor colorWithWhite:0.3 alpha:0.1]];
    [_gotoButton setBackgroundImage:[UIImage imageNamed:@"skip_selected"] forState:UIControlStateHighlighted];
    [_gotoButton setTitle:@"跳过" forState:UIControlStateNormal];
    [_gotoButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_gotoButton addTarget:self action:@selector(skipThisView) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_gotoButton];
    
    
    
}

- (void)skipThisView{
//    AppDelegate *delegagte = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//    FilterViewController *filterVC = [[FilterViewController alloc] init];
//    filterVC.view.frame = delegagte.window.frame;
//    delegagte.window.rootViewController = filterVC;
//    [delegagte.window makeKeyAndVisible];
}



- (void)addImageViews{
    NSArray *array = [NSArray arrayWithObjects:@"lanunch_1", @"lanunch_2", @"lanunch_3", @"lanunch_4", nil];
    for (int i = 0; i < array.count; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:array[i]]];
        imageView.frame = CGRectMake(i * kScreenWidth, 0, kScreenWidth, kScreenHeight);
        imageView.userInteractionEnabled = YES;
        imageView.contentMode = UIViewContentModeScaleToFill;
        [_scrollView addSubview:imageView];
    }
}




- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    int current = scrollView.contentOffset.x/self.view.bounds.size.width;
    if (current == 3) {
        UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(skipThisView)];
        [self.scrollView addGestureRecognizer:tap];
    }
}
@end
